<?php

class UserRecord extends TActiveRecord
{
	const TABLE='tbl_user';

	public $ID;
	public $Username;
	public $Password;
	public $Email;
	public $FirstName;
	public $LastName;
	public $Gender;
	public $Address;
	public $City;
	public $Country;
	public $PostalCode;
	public $Phone;
	public $Phone2;
	public $Newsletter;
	public $UserType;
	public $Credits=0;
	public $CreditsUsed=0;
	public $Status=0;
	public $Hash="";
	public $IPAddress="";
	public $LastVisitIP="";
	public $LastVisitDate=0;
	public $CreateBy;
	public $CreateDate;
	public $ModifyBy;
	public $ModifyDate;
	
	public static $COLUMN_MAPPING=array
	(
		'user_id'=>'ID',
		'user_name'=>'Username',
		'user_pwd'=>'Password',
		'user_email'=>'Email',
		'first_name'=>'FirstName',
		'last_name'=>'LastName',
		'gender'=>'Gender',
		'address'=>'Address',
		'city'=>'City',
		'country'=>'Country',
		'postal_code'=>'PostalCode',
		'phone'=>'Phone',
		'phone2'=>'Phone2',
		'newsletter'=>'Newsletter',
		'user_type'=>'UserType',
		'user_credits'=>'Credits',
		'user_credits_used'=>'CreditsUsed',
		'user_status'=>'Status',
		'user_hash'=>'Hash',
		'ip_address'=>'IPAddress',
		'last_visit_ip'=>'LastVisitIP',
		'last_visit_date'=>'LastVisitDate',
		'c_by'=>'CreateBy',
		'c_date'=>'CreateDate',
		'm_by'=>'ModifyBy',
		'm_date'=>'ModifyDate'
	);

	public static function finder($className=__CLASS__)
	{
		return parent::finder($className);
	}
	
	public function save()
	{
		if ($this->ID <= 0)
		{
			$this->CreateDate = time();
		}
		$this->ModifyDate = time();
		parent::save();
	}
	
	public function getAllItems()
	{
		$criteria = new TActiveRecordCriteria;
		$criteria->Condition = "user_id > 0";
		return self::finder()->findAll($criteria);
	}
	
	public function getAllItemsOrderByFirstName()
	{
		$criteria = new TActiveRecordCriteria;
		$criteria->Condition = "user_id > 0 order by first_name asc";
		return self::finder()->findAll($criteria);
	}
}
?>